<?php
/*
* @desc 个人定制控制类
* @author kevin.wang
* @date 2015-01-01 12:00:00
*/
class CustomizeController extends Controller
{
	public  $layout = '/layouts/base';
	//过滤器
	public function filters()
    {
        return array(
            'UserLogin + book',
        );
    }
	//定制首页
	public function actionIndex()
	{
		$this->render('index');
	}
	//定制功能
	public function actionBook(){
		$data = array('status' => 0, 'body' => array());
		if(!Yii::app()->request->isAjaxRequest){
			$data['status'] = 10002;
			$this->renderJson($data);
		}
		$customizeForm = Yii::app()->request->getParam("customizeForm");
		$model = new CustomizeForm;
		$model->attributes = $customizeForm;
		if(!$model->validate() || !$model->book()){
			$msg = array_values($model->getErrors());
			$data['status'] = 10000;
			$data['msg'] = $msg[0];
			$this->renderJson($data);
		}
		$this->renderJson($data);
	}
	//用户登录过滤
	function filterUserLogin($filterChain){
		$model = new LoginForm();
		$result = $model->userIsLogin();
		$data = array('status' => 0, 'body' => array());
		if(empty($result)){
			$data['status'] = 10001;
			$data['body'] = array('returnUrl'=>Yii::app()->createUrl("user/index"));
			$this->renderJson($data);
		}
		$filterChain->run();
	}
}
